<?php
	require "page.class.php";
    $connetc=mysql_connect("localhost","root","192510");
	mysql_select_db("news",$connetc);
	
    $sql2="select count(*) as amount from news";
	$result2=mysql_query($sql2);
	$row2=mysql_fetch_array($result2);
	$count=$row2['amount'];//总条数
	$pagesize=10;//每页显示的条数
	$title=$_GET['title'];
	$web=$_GET['web'];
	$author=$_GET['author'];
	$send_time1=$_GET['send_time1'];
	$send_time2=$_GET['send_time2'];

	if($count%$pagesize){
		$page=ceil($count/$pagesize);
	}else{
		$page=$count/$pagesize;
	}
	
	if(isset($_GET['currentpage'])){
		$currentpage=intval($_GET['currentpage']);
    }else{
		$currentpage=1;
    }
if($title==null&&$web==null&&$author==null&&$send_time1==null&&$send_time2==null){//查询全部
     $sql2="select count(*) as amount from news";
	 $result=mysql_query($sql2);
	 $row=mysql_fetch_array($result);
     $count=$row['amount'];//总条数
	 if($count%$pagesize){
		 $page=ceil($count/$pagesize);
	 }else{
		$page=$count/$pagesize;
	 }
	 if(isset($_GET['currentpage'])){
		$currentpage=intval($_GET['currentpage']);
	 }else{
		$currentpage=1;
	 }
	 $start=($currentpage-1)*$pagesize;
	 
	 $sql="select * from news order by publishtime desc limit $start,$pagesize";
	 $result = mysql_query($sql);


}else{//条件查询

	  //得到标题
	   $title_array=array();
	   $title_array=explode(",",$title);
	   $strt1=" title like '%{$title_array[0]}%'";
	   for($i=1;$i<count($title_array);$i++){
		  $strt2.=" or title like '%{$title_array[$i]}%'";
	   } 
	   $rel_title="(".$strt1.$strt2.")";
	   
	    //得到作者
		 $author_array=array();
		 $author_array=explode(",",$author);
		 $stra1=" and (author like '%{$author_array[0]}%'";

		 for($i=1;$i<count($author_array);$i++){
			 $stra2.=" or author like '%{$author_array[$i]}%'";
		 }
		 
		 $rel_author=$stra1.$stra2.")";
		 

		 //得到网站
		 $web_array=array();
		 

		 if($web==null){
			 
			 if($send_time1==null&&$send_time2==null){
				 $rel_sql=$rel_title.$rel_author;
				 
			 }else{
				 //得到时间
					 $rel_time=" and publishtime>='$send_time1' and publishtime<='$send_time2'";
					 $rel_sql=$rel_title.$rel_author.$rel_time;
			 }
			
		 }else{
			 
				 $web_array=explode(',',$web);
				 $strw1= $stra1=" name like '%{$web_array[0]}%'";
				 for($i=1;$i<count($web_array);$i++){
					 $strw2.=" or name like '%{$web_array[$i]}%'";
				 }
				 
				 $rel_web=$strw1.$strw2;
				 
				 //根据模糊查询得到数字的网站
				 $web_sql="select * from wangzhan where".$rel_web;
				 $web_result=mysql_query($web_sql);
				 $web_array2=array();
				 while($web_row=mysql_fetch_array($web_result)){
					 
					  array_push($web_array2,$web_row['id']);
					  
				 }
				 
				 //得到数字网站
				  $web_strw1=" and (web={$web_array2[0]}";
				  for($i=1;$i<count($web_array2);$i++){
					 $web_strw2.=" or web={$web_array2[$i]}";
				  } 
				 $rel_web2=$web_strw1.$web_strw2.")";
				
				 
			 if($send_time1==null&&$send_time2==null){
				 $rel_sql=$rel_title.$rel_author.$rel_web2;
				 
			 }else{
				  //得到时间
				 $rel_time=" and publishtime>='$send_time1' and publishtime<='$send_time2'";
				 $rel_sql=$rel_title.$rel_author.$rel_web2.$rel_time;
			 }

		 }
		
		//总条数
		 $sql2="select count(*) as amount from news where ".$rel_sql;
		 $result=mysql_query($sql2);
		 $row=mysql_fetch_array($result);
		 $count=$row['amount'];//总条数
		 if($count%$pagesize){
		    $page=ceil($count/$pagesize);
		 }else{
			$page=$count/$pagesize;
		 }
		 if(isset($_GET['currentpage'])){
			$currentpage=intval($_GET['currentpage']);
		 }else{
			$currentpage=1;
		 }
		 $start=($currentpage-1)*$pagesize;
		 
         $sql="select * from news  where".$rel_sql." order by publishtime desc limit $start,$pagesize";
		 $result = mysql_query($sql);
		 
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="js/select-ui.min.js"></script>
<script type="text/javascript" src="editor/kindeditor.js"></script>
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="../time/jquery.datetimepicker.css"/>
<script src="../time/jquery.js"></script>
<script src="../time/jquery.datetimepicker.js"></script>
<style>
.tip{
    width:620px;
	height:600px;
}
.tip1{
    width:600px;
	height:600px;
}

</style>
<script type="text/javascript">
 KE.show({
    id : 'content7',
    cssPath : './index.css'
 });
$(document).ready(function(){
  $(".click").click(function(){
  $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
  $(".tip").fadeOut(200);
  });

  $(".tiptop1 a").click(function(){
  $(".tip1").fadeOut(200);
  });
  


});
</script>
<script type="text/javascript">
$(document).ready(function(e) {

	$(".select3").uedSelect({
		width : 152
	});
});
</script>
</head>

<body onload="document.body.scrollTop=document.body.scrollHeight">
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">新闻管理</a></li>
    <li><a href="#">新闻列表</a></li>
    </ul>
    </div>
    
    <div class="formbody">
	
    <div id="usual1" class="usual">
	<form action="select_new.php" method="get">
    <ul class="seachform1">
    <li><label>新闻标题</label><input  type="text" class="scinput1" name="title" value="<?php echo $title;?>"/></li>
    <li><label>来源网站</label><input  type="text" class="scinput1" name="web"  value="<?php echo $web;?>"/></li>
    <li><label>作者</label><input   type="text" class="scinput1" name="author"   value="<?php echo $author;?>"/></li>
    </ul>
	
	<ul class="seachform1">
    <li><label>起始时间</label><input type="text" class="scinput1" id="send_time1" onclick="time1();" name="send_time1" value="<?php echo $send_time1;?>"/></li>
    <li><label>终止时间</label><input type="text" class="scinput1" id="send_time2" onclick="time2();" name="send_time2" value="<?php echo $send_time2;?>" /></li>
    </ul>
	
    <ul class="seachform1">
    <li><label>&nbsp;</label><input type="submit" class="scbtn" value="查询"/></li>
    </ul>
	
	</form>
    <script language="javascript">
	
	$(document).ready(function() 
    { 
    $(".scbtn1").click(function() 
    {      
        if( $(".seachform2").hasClass("hideclass") ) 
        { 
            $(".seachform2").removeClass("hideClass"); 
        } 
        else 
        { 
            $(".seachform2").addClass("hideClass"); 
        }    
    }); 
  }); 
	
	</script>
	
    <script type="text/javascript">
    $(document).ready(function(){
      $(".scbtn1").click(function(){
      $(".seachform2").fadeIn(200);
    }); 
   });
</script>
    <div class="formtitle"><span>项目列表</span></div>
    <div class="tools">
      <ul class="toolbar">
      <li onclick="ck(0)"><span><img src="images/t01.png" /></span>添加</li>
      <li onclick="deletebatch()"><span><img src="images/t03.png"/></span>删除</li>
      </ul>
    </div>
    <table class="tablelist">
    	<thead>
    	<tr>
        <th><input type="checkbox" onclick="selectAll(this)"/></th>
        <th>新闻标题</th>
        <th>来源网站</th>
        <th>作者</th>
        <th>发布时间</th>
        <th>操作</th>
        </tr>
        </thead>
        <tbody>
		<?php
		 while($row=mysql_fetch_array($result)){
		?>
        <tr>
        <td><input type="checkbox"  name="son_checkbox" value="<?php echo $row['id'];?>"/></td>
        <td><a target="_blank" href="<?php echo $row['link']; ?>"><?php echo $row['title'];?></a></td>
        <td>
		<?php
		$web_id=$row['web'];
		$sql_web="select * from wangzhan where id=$web_id";
		$result_web=mysql_query($sql_web);
		$row_web=mysql_fetch_assoc($result_web);
		echo $row_web['name'];
	
		?>
		</td>
        <td><?php echo $row['author'];?></td>
        <td><?php echo $row['publishtime'];?></td>
        <td><a href="#" onclick="ck2('<?php echo $row['id'];?>')" class="tablelink">查看</a> <a href='#' class="tablelink" onclick="ck('<?php echo $row['id'];?>')">修改</a> <a href="delete_new.php?id=<?php echo $row['id'];?>" class="tablelink"> 删除</a></td>
        </tr> 		
		<?php	
			}
		?>
        </tbody>
    </table>
     <div class="pagin">
    	<?php
			pagelinks();
	    ?>
    </div>
     
	<div class="tip">
       <div class="tiptop"><span>新闻栏目</span><a></a></div>
       <div class="formbody">
	   <form method="post" action="insert_new_commit.php">
	   <input type="hidden" name="id" id="id"/>
       <ul class="forminfo">
       <li><label>标题</label><input  name="title" onblur="new_name();"   id="title" class="dfinput" /><i style="margin-right:20px;display:none;" id="yz_title">标题不能为空</i></li>
       <li><label>网站</label>
	   <input type="test" name="web" disabled="true"  id="web" class="dfinput" size="35" value="无"/> 			
	  </li>
      <li><label>作者</label><input  type="text" class="dfinput" name="author" id="author"/></li>
      <li><label>内容</label><textarea cols="42" rows="5" name="content" id="content" style="width:340px;height:80px;overflow-y:visible" class="textinput"></textarea></li>
	  <li><label>链接</label><input type="text" class="dfinput"  name="link" id="link"/></li>
      <li><label>&nbsp;</label><input  type="submit" class="btn" value="确认保存" onclick="return tijiao();"/></li>
      </ul>
	  </form>
      </div>
    </div>
	
	<div class="tip1">
       <div class="tiptop1"><span>新闻详情</span><a></a></div>
       <div class="formbody">
	    <ul class="forminfo">
	    <li><label>链接</label><input type="text" class="dfinput"  name="link1" id="link1" disabled="disabled" /></li>
	    <li><label>内容</label><textarea cols="42" rows="5" name="content1"  id="content1" style="resize:none;width:340px;height:300px;" disabled="disabled" class="textinput"></textarea></li>
        </ul>
	  </div>
    </div>
	
	</div>
    </div>
</body>
</html>
<script>
      document.write(new Array(100).join("<br>"));
	   
	   
       $('#send_time1').datetimepicker({
		   
			timepicker:false,
			format:'Y-m-d',
	
	   });
	
	
	  $('#send_time2').datetimepicker({
	     timepicker:false,
		 format:'Y-m-d',
	
	  });
        // function time(){
		//	$('#send_time1').datetimepicker({
	
				//timepicker:false,
				//format:'Y-m-d',
	
			//});
			
		//}
            
       // function time2(){
		//	$('#send_time2').datetimepicker({
	
			//	timepicker:false,
			//	format:'Y-m-d',
	
		//	});
	//	}			
		function new_name(){
		   var title=$("#title").val();
		   if(title==null||title.length==0){
			   $("#yz_title").show();
		   }else{
			    $("#yz_title").hide();
		   }
		   
	   }

		function tijiao(){
		 
		     var title=$("#title").val();
			 if(title==null||title.length==0){
				 alert("新闻名不能为空");
				 return false;
				 
			 }else{
				 
				 return true;
			 }
		   
		   
		   
	   }
	   
       function selectAll(objs){
		   
		     obj=document.getElementsByName('son_checkbox');
			 for(var i=0;i<obj.length;i++){
				 
				 if(objs.checked){
					 obj[i].checked=true;
				 }else{
					 obj[i].checked=false;
				 }
				 
			 }
			 
	   }
	   
	   function deletebatch(){
		   
		   obj=document.getElementsByName('son_checkbox');
		   var arrayid=new Array();
		   for(var i=0;i<obj.length;i++){
			   
			   if(obj[i].checked){
				  
				  arrayid.push(obj[i].value);
				  
			   }
		   }
		   
		   if(arrayid.length==0){
			   
			   alert("请选择需要删除的任务");
			   
		   }else{
			   
			   
			   if(confirm("确定要删除所选择的新闻吗")){
				  
				  $.post('delete_new.php',{arrayid:arrayid},function(data){
					window.location.reload();
			      });
				  
			  }else{
				  return false;
			  }
			   
			   
		   }
			   
	   }
	   
	   function ck(id){
		   if(id==0){
			   //添加新闻
			   $("#title").val("");
			   $("#web").val("无");
			   $("#author").val("");
			   $("#content").val("");
			   $("#link").val("");
			   $("#id").val("");
		   }else{
			   //编辑新闻
               $.post("select_news_id.php",{id:id},function(data){
				    $("#title").val(data['title']);
					var web=data['web'];
					//得到新闻的链接
					$.post("get_wangzhan.php",{web_id:web},function(data){
						var web_name=data['name'];
                        $("#web").val(web_name);
					},"json");
					$("#author").val(data['author']);
					$("#id").val(data['id']);
					$("#content").val(data['content']);
					$('#link').attr("disabled",true); 
					$("#link").val(data['link']);
					
			   },"json")			   
		   }
		   $(".tip").fadeIn(200); 
	   }
	   
	   function ck2(id){
		   
		      $.post("select_news_id.php",{id:id},function(data){
					$("#content1").val(data["content"]);
					$("#link1").val(data["link"]);
				 
			  },"json")
		      $(".tip1").fadeIn(200); 
	   }
</script>
